// pages/login/login.js
import {
    LOGIN,
} from '../../request/api'
var base64 = require('../../utils/base64.js')
const { md5 } = require("../../utils/md5.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userName: '',
        password: ''
    },

    submit() {
        let param = {
            loginName: this.data.userName,
            password: md5(this.data.password),
            origin: 1
        }
        if (!param.loginName || !param.password) {
            wx.showToast({
                title: '请输入用户名/密码',
                icon: 'none',
                duration: 2000
            })
            return
        }
        LOGIN(param).then(response => {
            wx.setStorage({
                data: response.token,
                key: 'token',
            })
            wx.redirectTo({
              url: "/pages/index/index",
            })
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})